<template>
  <div class="page-account">
    <div v-if="showI18n" class="page-account-header">
      <i-header-i18n />
    </div>
    <div class="page-account-container">
      <div class="page-account-top">
        <div class="page-account-top-logo">
          <img src="@/assets/images/dodoke.png" alt="logo" />
        </div>
        <div class="page-account-top-desc">
          <h1>Hello, world!</h1>
          <p>欢迎来到渡课IT教育在线判题系统——渡课 Online Judge</p>
        </div>
      </div>
      <Login @on-submit="handleSubmit">
        <UserName name="username" value="" />
        <Password name="password" value="" enter-to-submit />
        <Submit>{{ $t("page.login.submit") }}</Submit>
      </Login>
<!--      <div class="page-account-other" >-->
<!--        <a href="">{{ $t("page.login.forgot") }}?</a>-->
<!--        <router-link class="page-account-register" :to="{ name: 'register' }">{{-->
<!--          $t("page.login.signup")-->
<!--        }}</router-link>-->
<!--      </div>-->
    </div>
    <i-copyright />
  </div>
</template>
<script>
import iCopyright from "@/components/copyright";
import { mapActions } from "vuex";
import mixins from "../mixins";
// import { usersLogin}  from "@/api/login";

export default {
  mixins: [mixins],
  components: { iCopyright },
  data() {
    return {
      autoLogin: true
    };
  },
  methods: {
    // ...mapActions("admin/account", ["login"]),
    ...mapActions("account", ["login"]),
    /**
     * @description 登录
     * 表单校验已有 iView Pro 自动完成，如有需要修改，请阅读 iView Pro 文档
     */
    handleSubmit(valid, values) {
      //方法一
      // if (valid) {
      //   usersLogin(values).then((res) => {
      //     console.log(res);
      //     localStorage.setItem('token',res.token);
      //     console.log(localStorage.getItem("token"));
      //     this.$router.push({ path: '/' });
      //   });
      // }


      //方法二
      if (valid) {
        const { username, password } = values;
        this.login({
          username,
          password
        }).then(() => {
          this.$router.push({ path: '/' });
        });
      }
    }
  }
};
</script>
